<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>新增客户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css" th:href="@{/xadmin/css/font.css}">
    <link rel="stylesheet" href="./css/xadmin.css" th:href="@{/xadmin/css/xadmin.css}">
    <script src="./lib/layui/layui.js" charset="utf-8" th:src="@{/xadmin/lib/layui/layui.js}"></script>
    <script type="text/javascript" src="./js/xadmin.js" th:src="@{/xadmin/js/xadmin.js}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>客户名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify=""
                           autocomplete="off"
                           class="layui-input"></div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span><span id="nameInfo">唯一标识</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="address" class="layui-form-label">
                    <span class="x-red">*</span>地址</label>
                <div class="layui-input-inline">
                    <input type="text" id="address" name="address" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="phonenumber" class="layui-form-label">
                    <span class="x-red">*</span>联系电话</label>
                <div class="layui-input-inline">
                    <input type="text" id="phonenumber" name="phonenumber" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer', 'jquery'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //表单验证以及检测用户名是否存在
        $("#goodsnumber").blur(function () { //文本框鼠标焦点消失事件
            var goodsnumber = $("#goodsnumber").val();
            if (goodsnumber != "") {
                var reg_number = /^\w{4,10}$/;
                var flag = reg_number.test(goodsnumber);
                if (!flag) {
                    $("#goodsnumberInfo").html("格式不正确，请输入4-10位");
                } else {
                    $.get("checkgoodsnumber?goodsnumber=" + goodsnumber, function (data) //此处get方式 可换为post方式按需求调整，其他无需修改使用方式一样
                    {
                        if (data == "no") {
                            $("#goodsnumberInfo").html("<a th:href='@{/goods-edit}'>该货物已存在！</a>"); //向ID为goodsnumberInfo的元素内添加html代码
                        } else {
                            $("#goodsnumberInfo").html(""); //向ID为chk的元素内添加html代码
                        }
                    });
                }
            }
        })


        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);//控制台打印
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6}, function () {
                $.post('customeradd', data.field, function (data) {
                    if (data == 1) {
                        layer.msg("添加成功！");
                        //关闭当前frame
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    } else {
                        layer.msg("添加失败！");
                    }
                })
                //关闭当前frame
                //xadmin.close();

                // 可以对父窗口进行刷新
                //xadmin.father_reload();
            });
            return false;
        });

    });</script>
</body>
</html>
